//主从表tab选项卡标志位
var A0797F_Tab_Flag = -1;
//选择某一行
var A0797F_select_t_sys_file_rowId = "";
//按钮事件新增或编辑
var A0797F_type = "";
//其他页面传到本页面参数
var A0797F_param = {};
//table选中数据，如无则默认第一条
var A0797F_rowCheckData = null;
//表格数据服务端分页或客户端分页 1:服务端 0:客户端
var A0797F_table_page = 1;

/*定义查询条件变量*/
/*declare query param begin*/

/*declare query param end*/

/*定义下拉框集合定义*/
/*declare select options begin*/

/*declare select options end*/

/*绑定show监听事件*/
if(A0797F_Tab_Flag == -1){
	var A0797F_n = Get_RandomDiv("A0797F","");
	$(A0797F_n).bind("show", function(objTag){
		A0797F_Adjust_Sub_Sequ();
		if(!$(A0797F_n).is(":hidden") && A0797F_Tab_Flag > 0 && ("#"+objTag.currentTarget.id.toString()) == A0797F_n)
			A0797F_adjust_tab();		
	});
}

//设置主从表div顺序
function A0797F_Adjust_Sub_Sequ(){
	var temSubDivs = $("#content-main").find("div[data-id]");
	var MainDiv = $(Get_RandomDiv("A0797F",""));
	for(i = 0; i < temSubDivs.length; i++) {
		if(A0797F_Is_Sub_Div(temSubDivs[i].id)){
			$(temSubDivs[i]).before($(MainDiv));
			break;
		}
	}
}

//主从表传递参数
function A0797F_param_set(){
	/*Main Subsuv Table Param Begin*/
	
	/*Main Subsuv Table Param end*/
}

//业务逻辑数据开始
function A0797F_t_sys_file_biz_start(inputparam) {
	layer.close(ly_index);
	A0797F_param = inputparam;
	//主从表传递参数
	A0797F_param_set();	
    /*biz begin*/
    A0797F_init_t_sys_file()
	
    /*biz end*/
}

/*业务函数步骤*/
/*biz step begin*/

/*biz step end*/

/*查找框函数*/
/*find qry fun begin*/

/*find qry fun end*/

/*页面结束*/
function A0797F_page_end(){
	A0797F_adjust_tab();
}

//按钮弹窗
window.A0CCFC_Upd_EvaEvents = {'click #A0CCFC_btn_Upd': function (e, value, row, index) {
		A0CCFC_select_t_param_value_rowId = index.toString();
		$("#A0CCFC_btn_t_param_value_edit").click();
	}
	,'click #A0CCFC_btn_Del': function (e, value, row, index){
		A0CCFC_select_t_param_value_rowId = index.toString();
		$("#A0CCFC_btn_t_param_value_delete").click();
	}
	//按钮事件
	/*table button events begin*/

	/*table button events end*/
};

//按钮定义
function A0CCFC_Upd_EvaFormatter(value, row, index) {
	var btnHtml = "<div style=\"display: block;\">"
	btnHtml += "<button id=\"A0CCFC_btn_Upd\" class=\"btn btn-warning btn-edit\" ><strong><i class=\"fa fa-edit\"></i>修改</strong></button>";
	btnHtml += "&nbsp;<button id=\"A0CCFC_btn_Del\" class=\"btn btn-danger btn-del\" ><strong><i class=\"fa fa-remove\"></i>删除</strong></button>";
	/*table button defined begin*/
	
	/*table button defined end*/
	btnHtml += "</div>";
	return [btnHtml].join();
}

//附件信息显示列定义
var A0797F_t_sys_file = [
	{ 
		checkbox:true
	},
	/*table column begin*/
    {
        title: '主键',
        field: 'MAIN_ID',
        sortable: true,
        visible: false
    },
    {
        title: '原文件名称',
        field: 'OLD_FILE_NAME',
        sortable: true
        ,formatter: set_s_decode
    },
    {
        title: '新文件名称',
        field: 'NEW_FILE_NAME',
        sortable: true
        ,formatter: set_file_show
    },
    {
        title: '用户信息',
        field: 'LOGIN_ID',
        sortable: true
        ,formatter: set_s_decode
    },
    {
        title: '系统时间',
        field: 'CREATE_DATE',
        sortable: true
        ,formatter: set_time_decode
    },
    {
        title: '备注',
        field: 'S_DESC',
        sortable: true
        ,formatter: set_s_decode
    },
    {
        title: '附件后缀',
        field: 'FILE_ATT',
        sortable: true
        ,formatter: set_s_decode
    }
	
	/*table column end*/
];

//页面初始化
function A0797F_init_t_sys_file() {
	$(window).resize(function () {
		  $('#A0797F_t_sys_file_Events').bootstrapTable('resetView');
	});
	//附件信息查询条件初始化设置
	/*query conditions init begin*/
	
    /*query conditions init end*/
	
	$('#A0797F_btn_t_sys_file_query').click();
}

//查询接口
function A0797F_t_sys_file_query() {
    $('#A0797F_t_sys_file_Events').bootstrapTable("removeAll");
	//以下为特殊字段列表查询，无特殊字段时不需要
	var inputdata = {
		"param_name": "N01_sel_t_sys_file",
		"session_id": session_id,
		"login_id": login_id
		/*传递查询条件变量*/
        /*get query param begin*/
		
        /*get query param end*/
	};
	ly_index = layer.load();
	if(A0797F_table_page == 1){
		inputdata = {"N01_sel_t_sys_file":[]};
		A0797F_get_N01_sel_t_sys_file(inputdata);
	}
	else{
		delete inputdata["pageNumber"];
		delete inputdata["pageSize"];
		get_ajax_baseurl(inputdata, "A0797F_get_N01_sel_t_sys_file");
	}
}

//查询结果
function A0797F_get_N01_sel_t_sys_file(input) {
	layer.close(ly_index);
	//查询失败
    if (Call_QryResult(input.N01_sel_t_sys_file) == false)
        return false;
    A0797F_rowCheckData = null;
    //调整table各列宽度
    $.each(A0797F_t_sys_file, function (i, obj) {
		if(obj.title != undefined){
			obj.width = obj.title.length * 14 + 37;
		}
	});
    
	var s_data = input.N01_sel_t_sys_file;
    A0797F_select_t_sys_file_rowId = "";
    if(s_data.length > 0){
    	A0797F_rowCheckData = s_data[0]; 
    }
    //table对应的属性
    var temTableAtt = {};
    if(A0797F_table_page == 1){
    	temTableAtt["url"] = bizzUrl;
    	temTableAtt["method"] = "get";
    	temTableAtt["sidePagination"] = "server";
    	temTableAtt["queryParamsType"] = "limit";
    }
    else{
    	temTableAtt["url"] = null;
    	temTableAtt["method"] = null;
    	temTableAtt["sidePagination"] = null;
    	temTableAtt["queryParamsType"] = null;
    }
    $('#A0797F_t_sys_file_Events').bootstrapTable('destroy');
    $("#A0797F_t_sys_file_Events").bootstrapTable({
        uniqueId: 'main_id',
        search: !0,
        pagination: !0,
        showRefresh: !0,
        showToggle: !0,
        locale: "zh-CN",
        showColumns: !0,
        showExport: !0,
        exportDataType:"all",
        exportTypes:['excel'],
        iconSize: "outline",
        onClickRow: function (row, $element) {
            // 判断是否已选中
            if ($($element).hasClass("changeColor")) {
                $('#A0797F_t_sys_file_Events').find("tr.changeColor").removeClass('changeColor');
                A0797F_select_t_sys_file_rowId = "";
            }
            else {
                // 未点击则，为当前行添加 class='changeColor'
                $('#A0797F_t_sys_file_Events').find("tr.changeColor").removeClass('changeColor');
                $($element).addClass('changeColor');                　
                A0797F_select_t_sys_file_rowId = $element.attr('data-index');
                
                //设置子表查询条件
                /*set child table qry begin*/
                
                $($("#A0797F_TAB_MAIN").find(".active")[0]).click();
                /*set child table qry end*/
                //判断是否button按钮点击事件
        		if(typeof($("#A0797F_TAB_MAIN").find(".active")[0]) == "undefined" && A0797F_prev_btn != A0797F_btn){
        			A0797F_prev_btn = A0797F_btn;
        			if($("#"+A0797F_btn)[0] == undefined)
        				eval(A0797F_btn + "()");
        			else
        				$("#"+A0797F_btn).click();
        		}
            }
        },
		onDblClickRow: function (row){
			if(A0797F_param.hasOwnProperty("target_name"))
			{
				$("#"+A0797F_param["target_id"]).val(eval("row."+A0797F_param["sourc_id"].toUpperCase()));
				$("#"+A0797F_param["target_name"]).val(s_decode(eval("row."+A0797F_param["sourc_name"].toUpperCase())));				
				layer.close(A0797F_param["ly_index"]);
			}
		},
        toolbar: "#A0797F_t_sys_file_Toolbar",
        url: temTableAtt["url"],
        method: temTableAtt["method"],
        height:500,
        columns: A0797F_t_sys_file,
        data: s_data,
        pageNumber: 1,
        pageSize: 10, // 每页的记录行数（*）
        pageList: [10,50,100,1000,2000], // 可供选择的每页的行数（*）
        queryParams: A0797F_t_sys_file_queryParams,
        sidePagination: temTableAtt["sidePagination"],//"server", //服务端处理分页
	    queryParamsType : temTableAtt["queryParamsType"],//"limit",//设置为 ‘limit’ 则会发送符合 RESTFul 格式的参数.
        icons: {
            refresh: "glyphicon-repeat",
            toggle: "glyphicon-list-alt",
            columns: "glyphicon-list"
        },
        onPostBody:function(){
        },
        onLoadSuccess: function(input){
        	if(input.rows.length > 0)
        		A0797F_rowCheckData = input.rows[0]; 
        },
        onLoadError: function(err){
            console.log("error: "+err);
        },
        responseHandler:A0797F_Res_N01_sel_t_sys_file
    });
	A0797F_page_end();
}

//设置参数
function A0797F_t_sys_file_queryParams(inputdata){
	ly_index = layer.load();
	if(A0797F_table_page == 0)
		return null;
	var temdata = {
		"param_name": "N01_sel_t_sys_file",
		"session_id": session_id,
		"login_id": login_id
		/*传递查询条件变量*/
        /*get query param begin*/
        /*get query param end*/
	};	
	for (var key in temdata) {
		inputdata[key] = temdata[key];
    }
	if(inputdata.hasOwnProperty("offset") && inputdata.hasOwnProperty("limit")){
		inputdata["pageNumber"] = parseInt(inputdata["offset"] / inputdata["limit"]) + 1;
		inputdata["pageSize"] = inputdata["limit"];
	}
	else{
		inputdata["pageNumber"] = 0;
		inputdata["pageSize"] = 0;
	}
	return inputdata;
}

//获取接口数据
function A0797F_Res_N01_sel_t_sys_file(input){
	layer.close(ly_index);
	//查询失败
    if (Call_QryResult(input.N01_sel_t_sys_file) == false)
        return false;
    if(input["N01_sel_t_sys_file"].length > 0)
    	A0797F_rowCheckData = input["N01_sel_t_sys_file"][0];
    if(A0797F_table_page == 0)
		return null;
	else{ 
		var json_list = {};
		json_list["total"] = input["N01_sel_t_sys_file_ROWS"];
		json_list["rows"] = input["N01_sel_t_sys_file"];
		return json_list;
	}
}

//刷新按钮
$('#A0797F_btn_t_sys_file_refresh').click(function () {
	/*重置查询条件变量*/
	/*refresh query param begin*/

	/*refresh query param end*/

	/*重置下拉框集合定义*/
	/*refresh select options begin*/

	/*refresh select options end*/
	
	/*页面重置重新加载*/
	/*biz begin*/
    A0797F_init_t_sys_file()
	
    /*biz end*/
})

//查询按钮
$('#A0797F_btn_t_sys_file_query').click(function () {
	/*设置查询条件变量*/
    /*set query param begin*/
	
    /*set query param end*/
	A0797F_t_sys_file_query();
})

//vue回调
function A0797F_t_sys_file_call_vue(objResult){
	//选择某条记录或自动选择第一条
	if (A0797F_select_t_sys_file_rowId != "") 
		A0797F_rowCheckData = $("#A0797F_t_sys_file_Events").bootstrapTable('getData')[A0797F_select_t_sys_file_rowId];
	
	if(index_subhtml == "t_sys_file_$.vue")
	{
		var n = Get_RandomDiv("B0797F",objResult);	
		layer.open({
			type: 1,
	        area: ['1100px', '600px'],
	        fixed: false, //不固定
	        maxmin: true,
	        content: $(n),
	        success: function(layero, index){
				var inputdata = {"type":A0797F_type,"ly_index":index};
				if(A0797F_param.hasOwnProperty("hidden_find")){
					inputdata["hidden_find"] = "1";
				}				
				/*查询条件参数传递至子页面,初次加载*/
				/*Send One FindSelect param bgein*/
					
				/*Send One FindSelect param end*/
				
	        	loadScript_hasparam("sys_vue/t_sys_file_$.js","B0797F_t_sys_file_biz_start",inputdata);
	        },
			end: function(){
				$(n).hide();
			}
	    });
	}
	/*查询条件弹窗子页面*/
    /*get find subvue bgein*/
	
	/*get find subvue end*/
	
	/*tab页显示子页面*/
	/*get tab subvue begin*/

	/*get tab subvue end*/
}

//新增按钮
$("#A0797F_btn_t_sys_file_add").click(function () {
	A0797F_type = "add";
	index_subhtml = "t_sys_file_$.vue";
	if(loadHtmlSubVueFun("sys_vue/t_sys_file_$.vue","A0797F_t_sys_file_call_vue") == true){
		var n = Get_RandomDiv("B0797F","");
		layer.open({
			type: 1,
			area: ['1100px', '600px'],
			fixed: false, //不固定
			maxmin: true,
			content: $(n),
			success: function(layero, index){
				B0797F_param = {};
				B0797F_param["type"] = A0797F_type;
				B0797F_param["ly_index"]= index;
				if(A0797F_param.hasOwnProperty("hidden_find")){
					B0797F_param["hidden_find"] = "1";
				}
				/*查询条件参数传递至子页面,再次加载*/
			    /*Send Two FindSelect param bgein*/
				
				/*Send Two FindSelect param end*/

				B0797F_clear_edit_info();
			},
			end: function(){
				B0797F_clear_validate();
				$(n).hide();
			}
		});
	}
})

//编辑按钮
$("#A0797F_btn_t_sys_file_edit").click(function () {
	if (A0797F_select_t_sys_file_rowId != "") {
		A0797F_type = "edit";
		index_subhtml = "t_sys_file_$.vue";
		if(loadHtmlSubVueFun("sys_vue/t_sys_file_$.vue","A0797F_t_sys_file_call_vue") == true){
			var n = Get_RandomDiv("B0797F","");
			layer.open({
				type: 1,
				area: ['1100px', '600px'],
				fixed: false, //不固定
				maxmin: true,
				content: $(n),
				success: function(layero, index){
					B0797F_param = {};
					B0797F_param["type"] = A0797F_type;
					B0797F_param["ly_index"] = index;
					if(A0797F_param.hasOwnProperty("hidden_find")){
						B0797F_param["hidden_find"] = "1";
					}
					B0797F_clear_edit_info();
					B0797F_get_edit_info();
				},
				end: function(){
					B0797F_clear_validate();
					$(n).hide();
				}
			});
		}
	} else {
		swal({
            title: "提示信息",
            text: "无法修改记录，请选择正确记录修改!"
        });
    }
})

//删除按钮
$('#A0797F_btn_t_sys_file_delete').click(function () {
	//单行选择
	var rowData = $("#A0797F_t_sys_file_Events").bootstrapTable('getData')[A0797F_select_t_sys_file_rowId];
	//多行选择
	var rowDatas = A0797F_sel_row_t_sys_file();
	if (A0797F_select_t_sys_file_rowId != "" || rowDatas.length > 0) {
    	swal({
            title: "告警",
            text: "确认要删除吗?删除数据将无法恢复!",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            closeOnConfirm: false
        },
		function () {
        	if(rowDatas.length > 0)
        	{
	        	$.each(rowDatas, function (i, obj) {
					var delete_main_id = obj.MAIN_ID;
					var inputdata = {
						"param_name": "N01_del_t_sys_file",
						"session_id": session_id,
						"login_id": login_id,
						"param_value1": delete_main_id
					};
					ly_index = layer.load();
					get_ajax_baseurl(inputdata, "A0797F_N01_del_t_sys_file");
	        	});
        	}
        	else
        	{
        		var delete_main_id = rowData["MAIN_ID"];
				var inputdata = {
					"param_name": "N01_del_t_sys_file",
					"session_id": session_id,
					"login_id": login_id,
					"param_value1": delete_main_id
				};
				ly_index = layer.load();
				get_ajax_baseurl(inputdata, "A0797F_N01_del_t_sys_file");
        	}
		}); 
    } else {
    	swal({
            title: "提示信息",
            text: "无法删除记录，请选择正确记录删除!"
        });
    }
})

//删除结果
function A0797F_N01_del_t_sys_file(input) {
	layer.close(ly_index);
	if(Call_OpeResult(input.N01_del_t_sys_file) == true)
		A0797F_t_sys_file_query();
}

//附件显示
function set_file_show(value, row, index){
	var attF = value.substring(value.indexOf(".")+1,value.length).toUpperCase();
	var vt = basePath+contextPath+UpFilePath()+value
	if(attF == "JPG" || attF == "BMP"
		|| attF == "JPG" || attF == "JPEG"
		|| attF == "PNG" || attF == "GIF")
	{
		var vt = basePath+contextPath+UpFilePath()+value
		return "<a href=\""+vt+"\" target=\"_blank\"><img src=\""+vt+"\" style=\"width:100px\"/></a>";
	}
	else
	{
		return "<a href=\""+vt+"\" target=\"_blank\">"+value+"</a>";
	}
}

//特殊字符串数据解码
function set_s_decode(value, row, index) {
    return s_decode(value);
}

//时间数据解码
function set_time_decode(value, row, index) {
  var timeResult = s_decode(value);
  return timeResult.replace("T"," ");
}

//主从表选项卡动态添加
function A0797F_adjust_tab(){
	if(typeof($("#A0797F_TAB_MAIN")[0]) != "undefined" && $("#A0797F_TAB_MAIN")[0].length != 0){
		A0797F_Tab_Flag = 1;
		$(Get_RDivNoBuild("A0797F","")).find(".wrapper-content").css("padding","20px 20px 0px 20px");
		$(Get_RDivNoBuild("A0797F","")).find(".ibox").css("margin-bottom","0px");
		$(Get_RDivNoBuild("A0797F","")).find(".ibox-content").css("padding","15px 20px 0px");		
		$($("#A0797F_TAB_MAIN").find(".active")[0]).click();
	}
}

/*tab选项卡按钮点击事件*/
/*Tab Click Fun Begin*/
//隐藏tab页选项卡
function A0797F_hide_tab_fun(){
    var n = null;
}

//判断是否sub子项div页面
function A0797F_Is_Sub_Div(temDivId){
    if(temDivId.indexOf("XX$TTT") == 0)
        return false;
    return false;
}


/*Tab Click Fun End*/

function A0797F_show_tab_fun(inputUrl,inputrandom,temPar){
	index_subhtml = inputUrl;
	random_subhtml = inputrandom;
	if(loadHtmlSubVueFun("sys_vue/"+inputUrl,"A0797F_t_sys_file_call_vue") == true){
		var n = Get_RandomDiv(inputrandom,"");
		$(n).show();
		var rowData = null;
		//选择某条记录或自动选择第一条并传递参数
		if (A0797F_select_t_sys_file_rowId != "") 
			rowData = $("#A0797F_t_sys_file_Events").bootstrapTable('getData')[A0797F_select_t_sys_file_rowId];
		else
			rowData = A0797F_rowCheckData;
		//$("#A0797F_t_sys_file_Events").bootstrapTable('getData')[0];
		eval(inputrandom+"_param = {}");
		if(rowData != null){
			var temFlag = true;
			$.each(temPar, function (i, obj) {
				if(eval(inputrandom+"_param.hasOwnProperty(\""+obj.target_id+"\")") && eval(inputrandom+"_param[\""+obj.target_id+"\"]").toString() == rowData[obj.sourc_id].toString())
					temFlag = false;
				else
					eval(inputrandom+"_param[\""+obj.target_id+"\"] = \""+rowData[obj.sourc_id]+"\"");
			});
			if(temFlag){
				//传递子页面隐藏find功能
				eval(inputrandom+"_param[\"hidden_find\"] = \"1\"");
				//参数传递并赋值
				eval(inputrandom+"_param_set()");
				var tbName = inputUrl.substring(0,inputUrl.indexOf(".vue"));		
				eval(inputrandom+"_"+tbName+"_biz_start("+inputrandom+"_param)");
			}
		}
		else{
			$.each(temPar, function (i, obj) {
				if(obj.sourc_id.toUpperCase() == "MAIN_ID")
					eval(inputrandom+"_param[\""+obj.target_id+"\"] = \"-999\"");
				else
					eval(inputrandom+"_param[\""+obj.target_id+"\"] = \"\"");
				return;
			});
			//传递子页面隐藏find功能
			eval(inputrandom+"_param[\"hidden_find\"] = \"1\"");
			//参数传递并赋值
			eval(inputrandom+"_param_set()");
			var tbName = inputUrl.substring(0,inputUrl.indexOf(".vue"));		
				eval(inputrandom+"_"+tbName+"_biz_start("+inputrandom+"_param)");
		}
	}
}

//清除 查找框
function A0797F_clear_input_cn_name(obj1,obj2){
	$("#"+obj1).val("");
	$("#"+obj2).val("-1");
}

//选择多行数据进行业务操作
function A0797F_sel_row_t_sys_file(){
	//获得选中行
	var checkedbox= $("#A0797F_t_sys_file_Events").bootstrapTable('getSelections'); 
	//将选中行数据转成jsonStr
	var jsonStr=JSON.stringify(checkedbox);
	//将jsonStr转成jsonObject对象	 
	var jsonObject=jQuery.parseJSON(jsonStr);
	return jsonObject;
	//接着就可以遍历jsonObject数组对象，取出并操作数据
	//alert(jsonObject);
}
